home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_lib1 / rkrm_lib1.lha / Intuition / Requesters_Alerts / blockinput.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  6KB  |  218 lines

  1. ;/* blockinput.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 blockinput.c
  3. Blink FROM LIB:c.o,blockinput.o TO blockinput LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5. */
  6.  
  7. /*
  8. Copyright (c) 1992 Commodore-Amiga, Inc.
  9.  
  10. This example is provided in electronic form by Commodore-Amiga, Inc. for
  11. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  12. published by Addison-Wesley (ISBN 0-201-56774-1).
  13.  
  14. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  15. information on the correct usage of the techniques and operating system
  16. functions presented in these examples.  The source and executable code
  17. of these examples may only be distributed in free electronic form, via
  18. bulletin board or as part of a fully non-commercial and freely
  19. redistributable diskette.  Both the source and executable code (including
  20. comments) must be included, without modification, in any copy.  This
  21. example may not be published in printed form or distributed with any
  22. commercial product.  However, the programming techniques and support
  23. routines set forth in these examples may be used in the development
  24. of original executable software products for Commodore Amiga computers.
  25.  
  26. All other rights reserved.
  27.  
  28. This example is provided "as-is" and is subject to change; no
  29. warranties are made.  All use is at your own risk. No liability or
  30. responsibility is assumed.
  31. */
  32.  
  33. /*
  34. ** blockinput.c -- program to demonstrate how to block the input from a
  35. ** window using a minimal requester, and how to put up a busy pointer.
  36. */
  37. #define INTUI_V36_NAMES_ONLY
  38.  
  39. #include <exec/types.h>
  40. #include <intuition/intuition.h>
  41.  
  42. #include <clib/exec_protos.h>
  43. #include <clib/intuition_protos.h>
  44.  
  45. #include <stdio.h>
  46.  
  47. #ifdef LATTICE
  48. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  49. int chkabort(void) { return(0); }  /* really */
  50. #endif
  51.  
  52. /* our function prototypes */
  53. BOOL beginWait(struct Window *win, struct Requester *waitRequest);
  54. VOID endWait(struct Window *win, struct Requester *waitRequest);
  55. VOID processIDCMP(struct Window *win);
  56.  
  57. struct Library *IntuitionBase;
  58.  
  59. /* data for a busy pointer.
  60. ** this data must be in chip memory!!!
  61. */
  62. UWORD __chip waitPointer[] =
  63.     {
  64.     0x0000, 0x0000,     /* reserved, must be NULL */
  65.  
  66.     0x0400, 0x07C0,
  67.     0x0000, 0x07C0,
  68.     0x0100, 0x0380,
  69.     0x0000, 0x07E0,
  70.     0x07C0, 0x1FF8,
  71.     0x1FF0, 0x3FEC,
  72.     0x3FF8, 0x7FDE,
  73.     0x3FF8, 0x7FBE,
  74.     0x7FFC, 0xFF7F,
  75.     0x7EFC, 0xFFFF,
  76.     0x7FFC, 0xFFFF,
  77.     0x3FF8, 0x7FFE,
  78.     0x3FF8, 0x7FFE,
  79.     0x1FF0, 0x3FFC,
  80.     0x07C0, 0x1FF8,
  81.     0x0000, 0x07E0,
  82.  
  83.     0x0000, 0x0000,     /* reserved, must be NULL */
  84.     };
  85.  
  86.  
  87.  
  88. /*
  89. ** main()
  90. **
  91. ** Open a window and display a busy-pointer for a short time then wait for
  92. ** the user to hit the close gadget (in processIDCMP()).  Normally, the
  93. ** application would bracket sections of code where it wishes to block window
  94. ** input with the beginWait() and endWait() functions.
  95. */
  96. VOID main (int argc, char **argv)
  97. {
  98. struct Window *win;
  99.  
  100. if (IntuitionBase = OpenLibrary("intuition.library",37))
  101.     {
  102.     if (win = OpenWindowTags(NULL,
  103.                         WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_INTUITICKS,
  104.                         WA_Activate, TRUE,
  105.                         WA_Width,  320,
  106.                         WA_Height, 100,
  107.                         WA_CloseGadget, TRUE,
  108.                         WA_DragBar, TRUE,
  109.                         WA_DepthGadget, TRUE,
  110.                         WA_SizeGadget, TRUE,
  111.                         WA_MaxWidth, ~0,
  112.                         WA_MaxHeight, ~0,
  113.                         TAG_END))
  114.         {
  115.         processIDCMP(win);
  116.         CloseWindow(win);
  117.         }
  118.     CloseLibrary(IntuitionBase);
  119.     }
  120. }
  121.  
  122.  
  123.  
  124. /*
  125. ** beginWait()
  126. **
  127. ** Clear the requester with InitRequester.  This makes a requester of
  128. ** width = 0, height = 0, left = 0, top = 0; in fact, everything is zero.
  129. ** This requester will simply block input to the window until
  130. ** EndRequest is called.
  131. **
  132. ** The pointer is set to a reasonable 4-color busy pointer, with proper offsets.
  133. */
  134. BOOL beginWait(struct Window *win, struct Requester *waitRequest)
  135. {
  136. extern UWORD __chip waitPointer[];
  137.  
  138. InitRequester(waitRequest);
  139. if (Request(waitRequest, win))
  140.     {
  141.     SetPointer(win, waitPointer, 16, 16, -6, 0);
  142.     SetWindowTitles(win,"Busy - Input Blocked",(UBYTE *)~0);
  143.     return(TRUE);
  144.     }
  145. else
  146.     return(FALSE);
  147. }
  148.  
  149.  
  150.  
  151. /*
  152. ** endWait()
  153. **
  154. ** Routine to reset the pointer to the system default, and remove the
  155. ** requester installed with beginWait().
  156. */
  157. VOID endWait(struct Window *win, struct Requester *waitRequest)
  158. {
  159. ClearPointer(win);
  160. EndRequest(waitRequest, win);
  161. SetWindowTitles(win,"Not Busy",(UBYTE *)~0);
  162. }
  163.  
  164.  
  165. /*
  166. ** processIDCMP()
  167. **
  168. ** Wait for the user to close the window.
  169. */
  170. VOID processIDCMP(struct Window *win)
  171. {
  172. WORD done;
  173. struct IntuiMessage *msg;
  174. ULONG class;
  175. struct Requester myreq;
  176. UWORD tick_count;
  177.  
  178. done = FALSE;
  179.  
  180. /* Put up a requester with no imagery (size zero). */
  181. if (beginWait(win,&myreq))
  182.     {
  183.     /*
  184.     ** Insert code here for a window to act as the requester.
  185.     */
  186.  
  187.     /* We'll count down INTUITICKS, which come about ten times
  188.     ** a second.  We'll keep the busy state for about three seconds.
  189.     */
  190.     tick_count = 30;
  191.     }
  192.  
  193. while (!done)
  194.     {
  195.     Wait(1L << win->UserPort->mp_SigBit);
  196.  
  197.     while (NULL != (msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
  198.         {
  199.         class = msg->Class;
  200.         ReplyMsg((struct Message *)msg);
  201.  
  202.         switch (class)
  203.             {
  204.             case IDCMP_CLOSEWINDOW:
  205.                 done = TRUE;
  206.                 break;
  207.  
  208.             case IDCMP_INTUITICKS:
  209.                 if (tick_count > 0)
  210.                     {
  211.                     if (--tick_count == 0)  endWait(win,&myreq);
  212.                     }
  213.                 break;
  214.             }
  215.         }
  216.     }
  217. }
  218.